package com.kevin.miniospring;

import com.kevin.minio.config.MinioConfiguration;
import lombok.Data;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Properties;

/**
 * @author Kevin Liu
 * @date 2020/6/10 10:15 上午
 */
@Setter
public class PropertiesConfig {


    private Properties properties;

    private String defaultFileName = "minio.properties";

    public PropertiesConfig() {
        initProperties(defaultFileName);
    }

    public PropertiesConfig(String fileName) {
        initProperties(fileName);
    }

    private void initProperties(String fileName){
        try {
            properties = PropertiesLoaderUtils.loadAllProperties(fileName);
        } catch (IOException e) {
            throw new RuntimeException("load " + fileName +"  properties error");
        }
    }

    public String getProperty(String key){
        return properties.getProperty(key);
    }

}
